#ifndef __CODEC_H__
#define __CODEC_H__
#include "os/types.h"
#include "utils/byte_queue.h"
#include "bsp/bsp.h"

#define CH_START						0xF5
#define CH_END							0xF6
#define CH_ESC							0xF7
#define CH_ESC_START					0x05
#define CH_ESC_END						0x06
#define CH_ESC_ESC						0x07

typedef void (*frame_handler_t)(uint8_t *data, int len);
#define RX_FRAME_MAX_LEN 260
#define TX_CACHE_MAX_LEN CONFIG_UART_TX_BUFFER_SIZE
typedef struct{
    u8  hw_id;
    frame_handler_t call_back;
	u8  rx_frame[RX_FRAME_MAX_LEN];
	u16 rx_length;
	u16 rx_index;
	bool escape;
	bool start;
}decoder_t;

typedef struct {
    u8 hw_id;
    u8 tx_cache[TX_CACHE_MAX_LEN];
    byte_queue_t tx_queue;
    u16 crc;
}encoder_t;

void codec_init_decoder(decoder_t *decoder);
void codec_decoder_callback(void *param, u8 *buff, int size);
void codec_init_encoder(encoder_t *encoder);
void codec_encode_message(encoder_t *encoder, u8 *head, int head_size, u8 *data, int len);
static byte_queue_t *encoder_get_queue(encoder_t *enc) {
    return &enc->tx_queue;
}

#endif /* __CODEC_H__ */